package wch;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that DaRumble moves out of the line of enemy fire and from walls specified by strategy.
 * 
 * @author Christopher Wilson
 */
public class TestDaRumbleDodges extends RobotTestBed {
  /** True if the robot visited this corner during the test case. */
  boolean successfullyEscaped = false;

  /**
   * Specifies that Fire and DaRumble are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Fire,wch.DaRumble";
  }

  /**
   * This test runs for 20 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 20;
  }

  /**
   * After each turn, check to see if we are out of enemy's firing range.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the snapshot of the robot daRumble
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    // Get the snapshot of the enemy robot
    IRobotSnapshot enemy = event.getTurnSnapshot().getRobots()[0];
    // Get robot's current position
    double robotPos = robot.getBodyHeading();
    double enemyGunDegree = enemy.getGunHeading();

    // Checks to see if the robot position is not being in targeted position.
    if (enemyGunDegree != robotPos) {
      successfullyEscaped = true;
    }

  }

  /**
   * After the battle, check to see that we are out of the line of fire.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Escape Destination", successfullyEscaped);

  }

}
